package com.dpteam.dao.impl;

import com.dpteam.dao.PermissionDao;
import com.dpteam.model.Permission;
import com.dpteam.model.Role;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by xwh on 2016/1/8.
 */
@Repository
public class PermissionDaoImpl extends BaseDaoImpl<Permission> implements PermissionDao {

    @Override
    public List<Permission> findAllPermission() {
        String hql = "from Permission order by id ";
        return find(hql);
    }

    @Override
    public List<Role> findAllRoleByAuthorityType(String authorityType) {
        String hql = "from Permission where authorityType = ?";
        return get(hql, authorityType).getRoleList();
    }

    @Override
    public void deleteById(int id) {
        Permission permission = get(Permission.class, id);
        if (permission != null) {
            delete(permission);
        }
    }
}
